package com.github.mzule.fantasyslide.util;

import android.text.TextUtils;

import org.json.JSONObject;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;

public class NetUtils {
   static OkHttpClient okHttpClient = new OkHttpClient.Builder() .connectTimeout(10, TimeUnit.SECONDS) .writeTimeout(10,TimeUnit.SECONDS) .readTimeout(20, TimeUnit.SECONDS) .build();

public static void post(String url, Map<String,String> map, Callback mCallback){
    JSONObject jsonObject=new JSONObject();
    FormBody.Builder builder=new FormBody.Builder();
    for (String in : map.keySet()) {
        String str = map.get(in);
        if (!TextUtils.isEmpty(str)) {
            builder.add(in, str);
        }
    }
    FormBody formBody = builder.build();

    Request request = new Request.Builder() .url(url).post(formBody).build();
    //创建/Call
    Call call = okHttpClient.newCall(request); //加入队列 异步操作
    call.enqueue(mCallback);
}
}
